package io.renren.modules.dishes.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.utils.R;
import io.renren.modules.dishes.entity.RecipesVo;
import io.renren.modules.dishes.service.RecipesService;
import oracle.jdbc.proxy.annotation.Post;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/web/recipes")
public class RecipesController {

    @Autowired
    private RecipesService recipesService;


    @GetMapping("/list/{spuId}")
    public R getList(@PathVariable("spuId") String spuId){
        List<RecipesVo> res=recipesService.getListBySpuId(spuId);
        return R.ok().put("list",res);
    }

    @PostMapping("/save")
    public R addRecipes(@RequestBody RecipesVo recipesVo){
        recipesService.saveByVO(recipesVo);
        return R.ok();
    }


    @GetMapping("get/{recipesId}")
    public R getRecipesById(@PathVariable("recipesId") String recipesId){
        RecipesVo recipesVo=recipesService.getByRecipesId(recipesId);
        return R.ok().put("recipes",recipesVo);
    }

    @PostMapping("update")
    public R updateRecipes(@RequestBody RecipesVo recipesVo){
        recipesService.updateByVO(recipesVo);
        return R.ok();
    }

    @DeleteMapping("/delete/{recipesId}")
    public R deleteRecipes(@PathVariable("recipesId") String recipesId){
        recipesService.deleteById(recipesId);
        return R.ok();
    }


}
